Skip to content

feat(security): warn before sending credentials over plain http to non-loopback hosts - #5179

Open
thymikee wants to merge 9 commits into
mainfrom
feat/credential-transport-rule
Open

thymikee wants to merge 9 commits into
mainfrom
feat/credential-transport-rule

Conversation

@thymikee

@thymikee thymikee commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

First-party credentials belong on https:, or http: to loopback. For other URLs, 0.21.x warns on stderr once per origin per loaded package; 0.22 will refuse (insecure_credential_transport; one function flips). The warning is best effort. ADR: #5178.

Covers daemon, cloud (including refresh), Metro bridge, and default-transport proxy URLs. Insecure upload tickets are dropped unsent for the legacy upload. Daemon and Revyl share one loopback classifier.

Breaking: none on main. In 0.22, non-loopback http:// setups need encryption or AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT=1. The proxy package has no override: use https, a loopback upstream, or upstreamFetch.

  • Cloud URLs are judged where each flow reads them (login, refresh, profile); auth-session.ts is at the line cap.
  • New host-kit subpath: reusing an existing one grows 9–43 startup closures.
  • 170 added, 46 removed production lines (target ~150), including the moved classifier.

Before / after

Remote daemon at a plain-HTTP, non-loopback URL. Before: token sent silently. After:

Warning: credentials for http://remote-mac.example.test:7777 are sent in cleartext. agent-device 0.22 will refuse this. Use https, ssh -L, or Tailscale Serve, or set AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT=1.

Validation

At 0778c18ee6: nine changed test files, 70 passed. Live CLI against a local fake daemon with stderr closed: exit 0 with output (exit 1, no output, before). Lint, typecheck, and gates are left to CI.

Security

  • Each listed path is checked before its request.
  • The override must equal 1, from the sending process's host environment; profiles, tickets and requests cannot set it.
  • The Metro companion receives exactly the judged URL and token.
  • Messages show the origin only.
  • No redirect, wire-format, or provider URL changes.

🤖 Generated with Claude Code

thymikee and others added 2 commits November 28, 2026 13:50
…n-loopback hosts

A configured URL that receives a first-party credential should be https, or
plain http to a loopback host. agent-device 0.21.x warns on stderr, once per
origin, for any other URL; 0.22 will refuse with
reason insecure_credential_transport. Nothing breaks in this release.

Checked destinations: the remote daemon URL, the cloud URL (including the
stored issuer on refresh), the Metro bridge URL, and the @agent-device/proxy
upstream URL with its default transport. A direct-upload ticket that fails the
rule is dropped unsent and the upload takes the legacy route.

AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT=1 in the sending process's environment
allows plain http. @agent-device/proxy reads it from the new `env` option.

The daemon resolution and Revyl loopback classifiers now share one owner.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… digests

Two new contracts exports, and acks for the upload preflight declarations that
now judge a ticket URL locally. No request or response shape changes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.68 MB 6.68 MB +2.5 kB
Package (unpacked) 6.68 MB 6.68 MB +2.5 kB
Package (download) 2.04 MB 2.04 MB +709 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 18.5 ms 20.8 ms +2.3 ms
CLI --help 41.5 ms 43.1 ms +1.6 ms

Affected plugins

Plugin Installed (including dependencies) Unpacked Download
@agent-device/revyl 179.5 kB → 179.6 kB (+20 B) 179.2 kB → 179.2 kB (+20 B) 58.2 kB → 58.2 kB (+26 B)
@agent-device/testmu 26.1 kB → 26.1 kB (0 B) 25.7 kB → 25.7 kB (0 B) 9.4 kB → 9.4 kB (0 B)
@agent-device/tizen 97.5 kB → 97.5 kB (0 B) 97.1 kB → 97.1 kB (0 B) 34.4 kB → 34.4 kB (0 B)
@agent-device/webos 96.4 kB → 96.4 kB (0 B) 96.1 kB → 96.1 kB (0 B) 34.0 kB → 34.0 kB (0 B)

`createDaemonProxy` takes no environment option. The `agent-device proxy`
upstream is the local daemon on loopback, and an embedder with another plain
http upstream supplies `upstreamFetch` or uses https. The warning names those
fixes instead of an environment variable the proxy does not read.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread website/docs/docs/security-trust.md Resolved
Comment thread src/commands/schema/cli-help.ts Resolved
thymikee and others added 2 commits November 28, 2026 13:57
Login judges the URL it reads, and a refresh judges the stored issuer, before
either sends. This keeps auth-session.ts within the file line cap.

The ticket tests now assert that no request opens to the ticket host, and the
Metro test asserts the bearer it is judging. The docs limit the loopback claim
to the daemon and proxy listeners, and the CLI help says which process reads the
override.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Re-exporting it from an existing subpath would load the rule eagerly in every
importer: 43 entry closures grow through diagnostics, 9 through transport.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Three problems need a fix before merge at 5537b6e: the new warning can make a command fail, it can print twice, and two doc statements no longer match the client.

A second independent pass found that packages/host-kit/src/credential-admission.ts:21 can turn the 0.21.x warning into a fatal error. If a supervisor closes the stderr reader, a non-loopback HTTP daemon command with a daemon token can exit on an unhandled EPIPE. Cloud login, refresh and profile requests, Metro prepare, and a default proxy sending its upstream token use the same helper. In a standalone check on Node v26.11.1 (Darwin) with the reader closed, the run completed without the write and exited 1 with EPIPE with it. The warning must never change a command's outcome for any caller of the helper. Please make the shared write best effort and handle both synchronous errors and stream errors locally, as src/cli/auth-session.ts:961-980 does. To validate, run a command that warns with the stderr reader closed and show the same result as without the warning.

A second independent pass found that the packages/host-kit/src/credential-admission.ts:5 warnedOrigins set is not shared between published packages. tsdown.config.ts:85-88 and packages/proxy/tsdown.config.ts:8-17 bundle host-kit separately. An app that loads both the agent-device SDK and @agent-device/proxy can warn twice for one origin, against the per-process promise in website/docs/docs/security-trust.md:44. Every published bundle that includes this helper must share one warned-origin state per process, for example a set on a process-wide object under a stable symbol. To validate, load both built packages in one process, send credentials to the same origin through each, and show one warning.

A second independent pass found that website/docs/docs/remote-proxy.md:26 is now wrong about uploads. With an HTTPS tunnel, no --public-origin and no override, the client discards the HTTP proxy ticket (packages/remote/src/upload-client.ts:326-332) and sends the token and artifact over the original HTTPS daemon URL (packages/remote/src/upload-client.ts:131-138, packages/remote/src/upload-client.ts:240-256). So the flag is no longer required for uploads to use HTTPS. Every doc statement about --public-origin and HTTPS uploads should say that the flag gives direct-upload tickets an HTTPS origin, and that the client otherwise falls back to the HTTPS daemon URL. This covers this sentence and website/docs/docs/commands.md:2568.

Not blocking: these can be taken or left: call admitCredentialDestination directly from auth-session.ts instead of through the admitCloudUrl alias in src/cli/cloud-auth-request.ts:8 (or, if the line cap prevents that, keep the original name on the re-export), and append "(not @agent-device/proxy)" to the variable's row in website/docs/docs/configuration.md:151, because the proxy sends its upstream token without reading it.

None of the earlier inline threads still applies, so they can be resolved: #5179 (comment) (the single check at the Metro bridge URL, using the sender's trusted env, is correct as is), #5179 (comment) (fixed: the test now asserts that only loopback requests are sent), #5179 (comment) (fixed: the test now asserts the bridge authorization header), #5179 (comment) (fixed: the docs now separate loopback listeners from traffic between machines), and #5179 (comment) (fixed: the help text now names the process that needs the override).

All 26 checks pass at this commit.

Not verified here: no tests were run locally, and the ability of the ticket, daemon-client, cloud, Metro and proxy tests to catch a regression was judged by reading the code path without the guard, not by mutation. The override order inside buildCompanionEnv was taken from the author's account; only the single ensureMetroCompanion call site was checked. The path from a stored connection profile's daemonBaseUrl into the request flags was not traced, and the closure measurement in the PR description was not reproduced.

…utcome

A closed stderr reader turned the warning into an unhandled EPIPE: the command
exited 1 with no output. The write is now best effort.

The docs say the warning appears once per origin per loaded package, and that
`--public-origin` gives upload tickets an HTTPS origin while the client
otherwise uploads through the daemon URL.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Addressed the review of 5537b6e in 0778c18.

Closed stderr. Reproduced with the real CLI (session list against a local fake daemon addressed as 0.0.0.0, Node 26.11.1, macOS, no proxy variables), with the stderr reader closed:

Run Exit Output
5537b6e 1 none
0778c18 0 normal result
no warning (override) 0 normal result

A write callback alone does not help: in a standalone script it still exited 1, because the stream also emits error. The helper now attaches a one-time error listener before the write and catches synchronous throws. No stream wrapper.

Duplicate warning. I changed the wording to "once per origin per loaded package" instead of sharing state through a process-wide symbol. It is the smallest change, it matches the code, and a second line on stderr is harmless.

--public-origin. remote-proxy.md, commands.md and the proxy README now say the flag gives upload tickets an HTTPS origin and that otherwise the client uploads through the daemon URL. They also say older clients upload over plain HTTP, so operators keep a reason to set it.

Non-blocking. The configuration row now says "(not @agent-device/proxy)". The admitCloudUrl alias stays: using the original name wraps a line and puts auth-session.ts at 1,003 lines, over the cap.

The earlier inline threads are resolved.

* origin/main:
  fix(cli): judge install-from-source lease admission by its daemon command (#5169)
  ci: report sizes for affected plugins (#5176)
  fix(ios): keep the zh-Hans alert vocabulary check honest about OS versions (#5177)
  Consolidate Apple tap and replacement result construction (#5161)
  fix(daemon): retry provider lease record retirement (#5174)
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 7c36328

Since the review of 5537b6e: 0 new · 0 still open · 0 no longer raised

No open findings.

2 findings below minor hidden (user_settings.min_severity).

1 new finding away from what changed since 5537b6e not shown. Comment @apex-sentinel-staging review for a full review.

Reviewed with this repository's own Sentinel configuration (d2a4abe701be).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

The three problems from the earlier review are fixed at 7c36328, but the fix adds a listener leak on stderr that needs a change before merge.

A second independent pass found that packages/host-kit/src/credential-admission.ts:25 likely leaves a one-shot stderr error listener behind after each successful warning write. A long-running Node SDK host that sends authenticated daemon commands to 11 distinct non-loopback HTTP origins, with a working stderr and no override, gets MaxListenersExceededWarning on the 11th. A host that treats this warning as fatal exits before the command completes. An embedder that creates default-transport proxies for multiple upstreams reaches the same path (daemon-proxy.ts:580-599, daemon-proxy.ts:623-624). In an in-memory harness on Node v26.11.1 (Darwin) that ran the helper for 11 synthetic origins, 5537b6e retained no listeners and exited 0. 7c36328 retained 11 listeners and emitted the warning, and it exited 1 with no result when a process warning listener threw on it. Every warning write must keep error handling scoped to that write: a successful write leaves no listener behind, and synchronous errors and asynchronous EPIPE stay handled for every caller of the helper. Node Console’s best-effort stderr write inside the existing try block does this, as does its pattern of a temporary listener removed through the write callback. To validate, warn for 11 distinct origins in one process and show an unchanged stderr error listener count and no MaxListenersExceededWarning. Then close the stderr reader and show that a warning command ends with the same result as without the warning.

None of the earlier inline threads still applies, so they can be resolved: #5179 (comment) (the single check at the Metro bridge URL is correct as is), #5179 (comment) (fixed: the test asserts that only loopback requests are sent), #5179 (comment) (fixed: the test asserts the bridge authorization header), #5179 (comment) (fixed: the docs separate loopback listeners from traffic between machines), and #5179 (comment) (fixed: the help text names the sending process).

All 25 checks pass at this commit.

Not verified here: no local tests were run, the real CLI was not run with stderr closed (the guarded and unguarded writes were reproduced only in a standalone Node v26.11.1 script), and the two built packages were not loaded in one process (the per-package behavior was inferred from the build configs).

A successful write removes its listener, so many origins add none. A failed
write keeps it, because EPIPE is emitted after the write callback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Re: review of 7c36328. Fixed in 1fd11aa: the stderr error listener is now scoped to each warning write (credential-admission.ts).

  • A successful write removes its listener in the write callback.
  • A synchronous throw removes it in catch.
  • A failed asynchronous write keeps it. Node emits EPIPE after the write callback, so removing it there would make the error fatal. A failed write means stderr is already broken.

Validation:

  • Unit test: 11 distinct origins in one process leave process.stderr.listenerCount('error') unchanged, and no MaxListenersExceededWarning is emitted.
  • The sync-throw test now also checks that no listener is left.
  • Real process on Node v26.11.1: agent-device session list --json --daemon-base-url http://cleartext.invalid:9/agent-device, once with the stderr reader open and once with it destroyed. The outcome is identical, exit 1 with the same Remote daemon is unavailable JSON on stdout (the host is unreachable on purpose), and there is no EPIPE crash with stderr closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant